package com.yesido.javabase.collection;

import java.util.*;

/**
 * @author yesido
 * @description failfast和failsafe区别
 * @date 2023-06-10 22:27
 * @Version 8.3
 */
public class FastFail {
    public static void main(String[] args) {
        FailFast();
        testAsList();
    }

    private static void testAsList() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
        System.out.println(list);
    }

    private static void FailFast() {
        Map<String,String> mp = new HashMap<String,String>(){
            {
                put("name","mic");
                put("sex","male");
                put("age","18");
            }
        };
        Iterator<String> iterator = mp.keySet().iterator();
        /**
         * java.util包下的集合类都是快速失败的
         *  arraylist hashmap linkedlist都是快速失败的
         * java.util.concurrent 包下的容器都是安全失败的,可以在多线程下并发使用,并发修改。
         * 比如 concurrenthashmap copyonwirteArralist
         * Exception in thread "main" java.util.ConcurrentModificationException
         */
        while (iterator.hasNext()){
            System.out.println(mp.get(iterator.next()));
            mp.put("work","333");
        }
    }
}


